package pers.qianyu.controller;

import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.web.bind.annotation.*;
import pers.qianyu.model.comm.*;
import pers.qianyu.model.dto.*;
import pers.qianyu.model.vo.*;
import pers.qianyu.service.*;
import pers.qianyu.utils.*;

import javax.validation.*;
import java.util.*;

@Api("用户登录")
@RestController
public class LoginController {
    @Autowired
    private UserService userService;

    @ApiOperation("用户登录")
    @PostMapping("/login")
    public Results login(
            @ApiParam(name = "用户信息", value = "传入json格式", required = true)
            @RequestBody @Valid UserDTO userDTO) {
        UserVO userVO = userService.login(userDTO);
        return Results.ok("登录成功", JwtTokenUtil.createToken(userVO.getId() + "", Arrays.asList(userVO.getRoles())));
    }
}
